var website = "https://liveforce.ai"; var findOriging = window.location.origin.toString(); var url1 = website; var url2 = findOriging; function getMainDomain(hostname) { // Split the hostname by dots let parts = hostname.split('.'); // If there are only two parts, it's already the main domain (e.g., example.com) // If there are more than two parts, remove the first part (subdomain) if (parts.length > 2) { parts.shift(); } // Join the remaining parts back together return parts.join('.'); } function areSameDomain(url1, url2) { try { // Create URL objects let parsedUrl1 = new URL(url1); let parsedUrl2 = new URL(url2); // Get the main domains let mainDomain1 = getMainDomain(parsedUrl1.hostname); let mainDomain2 = getMainDomain(parsedUrl2.hostname); // Compare the main domains return mainDomain1 === mainDomain2; } catch (error) { console.error('Invalid URL:', error); return false; } } //if (areSameDomain(url1, url2)) { //console.log('The URLs have the same main domain.'); //} else { // throw new Error("Stopping script execution because origin matches " + mywebsite); //}